\documentclass[a4paper]{article}
\usepackage[affil-it]{authblk}
\usepackage{verbatim}
\usepackage{indentfirst}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{geometry}
\usepackage{xeCJK}
\geometry{margin=1.5cm, vmargin={0pt,1cm}}
\setlength{\topmargin}{-1cm}
\setlength{\paperheight}{29.7cm}
\setlength{\textheight}{25.3cm}

\begin{document}
% =================================================
\title{Numerical Analysis Programming homework \# 1}

\author{周川迪 3220101409}
\affil{强基数学2201}

\date{\today}

\maketitle

\begin{abstract}
  This report presents the solutions to the programming assignments of Chapter 1.
  The tasks is creating a base class EquationSolver that includes three methods, and imply 
  it on several equation-solving problems.
\end{abstract}

\section{Problem A}
\subsection{Function Abstract Base Class}
The abstract base class \texttt{Function} defines the interface for the equation to be solved. It includes:
\begin{itemize}
  \item A pure virtual function \texttt{operator()(double x) const} for evaluating the function at a given point $x$.
  \item A virtual function \texttt{derivative(double x, double h = 1e-6) const} that approximates the derivative 
  using the central difference method with a default step size $h = 1e-6$.
\end{itemize}

\subsection{Bisection Method}
The \texttt{Bisection\_Method} class implements the bisection method for finding the root of a continuous function within 
an interval $[a, b]$ where the function values at the endpoints have different signs. It includes:
\begin{itemize}
  \item Endpoints $a$ and $b$ of the interval.
  \item Tolerance levels \texttt{eps} and \texttt{delta} for the error and convergence checks.
  \item A maximum number of iterations \texttt{Maxiter}.
\end{itemize}
\subsection{Newton's Method}
The \texttt{Newton\_Method} class implements Newton's method for finding the root of a function using its derivative. It requires:
\begin{itemize}
  \item An initial guess \texttt{x0}.
  \item Tolerance level \texttt{eps} for the error check.
  \item A maximum number of iterations \texttt{Maxiter}.
\end{itemize}

\subsection{Secant Method}
The \texttt{Secant\_Method} class implements the secant method for finding the root of a function using two initial approximations. 
It includes:
\begin{itemize}
  \item Two initial guesses \texttt{x0} and \texttt{x1}.
  \item Tolerance level \texttt{eps} for the error check.
  \item A maximum number of iterations \texttt{Maxiter}.
\end{itemize}
\subsection{Check}
In each derived class, check whether the zero obtained by the EquationSolver method is a true zero by checking the function value.
If $|function value|$ is bigger than $100*eps$ $(1e-5)$, give warning output .

\section{Problem B}
Program output:
\verbatiminput{output_B.txt}

The bisection method can get the true zero of the first three function $F1$, $F2$ and $F3$.

But for the last function, the numerator of the function 
$F4(x) = \frac{x^3 + 4x^2 + 3x + 5}{2x^3 - 9x^2 + 18x - 2}$ is positive over the interval $[0, 4]$, it cannot be a zero of $F4$.

Actually, the "zero" we have found is a zero of the denominator. 
$F4$ goes to $-\infty$ and $+\infty$ on the left and right near $0.117877$.
Thus, the loop is terminated when the interval length is less than $\delta$, but the function value is close to infinity.

Luckily, the program can check the function value at this point, inspect this situation and issue a warning, enabling us to make further judgments.

\section{Problem C}
Program output:
\verbatiminput{output_C.txt}

Consider function $F5(x)=x-\tan(x)$ and the Newton method can get its true zero, which is a solution. 

\section{Problem D}
Program output:
\verbatiminput{output_D.txt}

I tried other initial values and obtained different results. 
It was found that when the secant method selects different points as initial values, 
if the continuous function has more than one zero, the results obtained through iteration may also be diverse.
Thus, the choice of initial point is very important.

\section{Problem E}
Program output:
\verbatiminput{output_E.txt}

The methods can solve out $h$, and the depth is $r-h$. Can guarantee an accuracy of 0.01 feet.

\section{Problem F}
Program output:
\verbatiminput{output_F.txt}

Get the solution of (a) (b) and for (c):
\begin{itemize}
  \item[c1] $x0=33^\circ$, $x1$ is far from $33^\circ$, the result is the same as (a).
  \item[c2] $x0=33^\circ$, $x1=$ is at another zero (not appropriate for the given situation), and the result is $\beta_{1}$.
  \item[c3] $x0$ and $x1$ are far from $33^\circ$ the result differs and is not appropriate for the given situation.
\end{itemize}

The Secant Method's effectiveness and the accuracy of the results are highly dependent on the selection of initial guesses. 

If the initial values are not chosen properly, the method might converge to an incorrect root or even fail to converge at all. 
So it's crucial to make a brief estimation and select initial values in a reasonable range not too far from the root.

Additionally, the initial values should not be too close to each other, as this can lead to a situation similar to the Newton's method, 
where the derivative approaches zero, causing potential failure of the method.

\section*{ \center{\normalsize {Acknowledgement}} }
1. \href{https://kimi.moonshot.cn}{Kimi AI}

2. \href{https://chat.openai.com}{ChatGPT},GPT-4o(free) and GPT 3.5
\end{document}